package day13.demo1.maipiao.demo1;

/**
 * @Auther:小陈的Java
 * 多线程卖票（100张票）-->
 */
public class WindowTest {
    public static void main(String[] args) {
        Window window1 = new Window("窗口1");
        Window window2 = new Window("窗口2");
        Window window3 = new Window("窗口3");
        window1.start();
        window2.start();
        window3.start();
    }
}
class Window extends Thread{
    private static  int ticket = 100;
    public Window(String name){
        super(name);
    }

    @Override
    public void run() {
        while (true){
            if(ticket>0){
                System.out.println(this.getName()+":卖票，卖第"+ticket+"票");
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                ticket--;
            }else {
                break;
            }
        }
    }
}